![]() |
PATH![]() |
![]() ![]() |
AppleScript defines the constants anything , current application , it , me , missing value , my , and result to help perform various tasks in your scripts. The constants it , me , and my are described in Using it, me, and my in Tell Statements.
The constant anything is rarely used in a script, though you might choose to do something like the following:
set myVariable to anything
-- perform operations that might change the value of myVariable
if myVariable is equal to anything then
-- perform certain steps, knowing the variable never got changed
else
-- perform other steps if the variable got changed
end if
Contrary to what you might think, the Boolean statement if myVariable is equal to anything evaluates to true only if myVariable is specifically equal to the constant anything. That is, comparing the contents of a variable to anything doesn't guarantee a true result.
You may also see anything as a parameter to an application command or to a scripting addition command. Here, the meaning is different, and does indicate that the command accepts any kind of input value for that parameter. For an example, see the With Data parameter of the Make command in the AppleWorks dictionary. Dictionaries describes how to examine a dictionary.
The current application is either the default target application or whatever application is currently set as a script's parent property. You can make any application the current application for a script or script object simply by declaring it as a parent property. Any subsequent command in the script for which the script doesn't have a handler is passed to the application you declare as the parent, and subsequent occurrences of the constant current application refer to that application.
For example, the following script declares the Finder as its parent property, then sends commands that close the Finder's frontmost window and return the application's name:
property parent: application "Finder"
close front window
tell current application to return my name --result: "Finder"
For more information, see The Parent Property and the Current Application.
The missing value constant is a placeholder for missing information. For example, if your script asks the Network Setup Scripting application for the zone of every connection, you might get back a list that showed the actual zone for every AppleTalk connection, but the item missing value for every TCP/IP connection because TCP/IP connections do not include a zone. If the current setup had two AppleTalk connections and two TCP/IP connections, the resulting list might look something like the following:
{"4th Floor South", "4th Floor North", missing value, missing value}
You could then perform operations such as the following, using the missing value constant:
if item 3 of myZoneList = missing value then
--do one thing if the connection does not report a zone
else
--do something else if the connection reports a zone
end if
AppleScript stores the result of a command in the predefined variable result . The value remains there until the next command is executed. If a command does not return a result, the value of result is undefined.
tell application "Finder"
count files in folder "Apple Extras" of startup disk
set numFiles to result -- Save result in numFiles variable.
end tell
For more information, see Using the Predefined Result Variable